package com.ruoyi.platform.service.impl;

import java.util.List;

import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.DateUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.platform.mapper.MMonitoringEquipmentMapper;
import com.ruoyi.platform.domain.MMonitoringEquipment;
import com.ruoyi.platform.service.IMMonitoringEquipmentService;

/**
 * 【请填写功能名称】Service业务层处理
 * 
 * @author dataControl
 * @date 2025-09-15
 */
@Service
public class MMonitoringEquipmentServiceImpl implements IMMonitoringEquipmentService 
{
    @Autowired
    private MMonitoringEquipmentMapper mMonitoringEquipmentMapper;

    /**
     * 查询【请填写功能名称】
     * 
     * @param equipmentId 【请填写功能名称】主键
     * @return 【请填写功能名称】
     */
    @Override
    public MMonitoringEquipment selectMMonitoringEquipmentByEquipmentId(Long equipmentId)
    {
        return mMonitoringEquipmentMapper.selectMMonitoringEquipmentByEquipmentId(equipmentId);
    }

    /**
     * 查询【请填写功能名称】列表
     * 
     * @param mMonitoringEquipment 【请填写功能名称】
     * @return 【请填写功能名称】
     */
    @Override
    public List<MMonitoringEquipment> selectMMonitoringEquipmentList(MMonitoringEquipment mMonitoringEquipment)
    {
        return mMonitoringEquipmentMapper.selectMMonitoringEquipmentList(mMonitoringEquipment);
    }

    /**
     * 新增【请填写功能名称】
     * 
     * @param mMonitoringEquipment 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int insertMMonitoringEquipment(MMonitoringEquipment mMonitoringEquipment)
    {
        if(ObjectUtils.isNotEmpty(mMonitoringEquipmentMapper.selectMMonitoringEquipmentByIpAddress(mMonitoringEquipment.getEquipmentIp()))){
            throw new ServiceException("该ip地址已经被其他设备绑定");
        }
        mMonitoringEquipment.setCreateTime(DateUtils.getNowDate());
        return mMonitoringEquipmentMapper.insertMMonitoringEquipment(mMonitoringEquipment);
    }

    /**
     * 修改【请填写功能名称】
     * 
     * @param mMonitoringEquipment 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int updateMMonitoringEquipment(MMonitoringEquipment mMonitoringEquipment)
    {
        MMonitoringEquipment existEquipment = mMonitoringEquipmentMapper.selectMMonitoringEquipmentByIpAddress(mMonitoringEquipment.getEquipmentIp());
        if(ObjectUtils.isNotEmpty(existEquipment)
            && !mMonitoringEquipment.getEquipmentId().equals(existEquipment.getEquipmentId())
        ){
            throw new ServiceException("该ip地址已经被其他设备绑定");
        }
        mMonitoringEquipment.setUpdateTime(DateUtils.getNowDate());
        return mMonitoringEquipmentMapper.updateMMonitoringEquipment(mMonitoringEquipment);
    }

    /**
     * 批量删除【请填写功能名称】
     * 
     * @param equipmentIds 需要删除的【请填写功能名称】主键
     * @return 结果
     */
    @Override
    public int deleteMMonitoringEquipmentByEquipmentIds(String[] equipmentIds)
    {
        return mMonitoringEquipmentMapper.deleteMMonitoringEquipmentByEquipmentIds(equipmentIds);
    }

    /**
     * 删除【请填写功能名称】信息
     * 
     * @param equipmentId 【请填写功能名称】主键
     * @return 结果
     */
    @Override
    public int deleteMMonitoringEquipmentByEquipmentId(String equipmentId)
    {
        return mMonitoringEquipmentMapper.deleteMMonitoringEquipmentByEquipmentId(equipmentId);
    }
}
